version: '2'
services:
  postgres:
    container_name: siriuso_dbms-postgresql
#    build: configs/docker/postgres
    image: postgres:12.7
    # image: postgres:alpine - будет последняя версия 
    environment:
      - POSTGRES_USER=siriuso
      - POSTGRES_PASSWORD=oGLOWo8nd3
      - POSTGRES_DB=siriuso
      - PGDATA=/home/postgresql/data
    volumes:
      - db:/home/postgresql
      - db:/var/log/postgresql
      - ./configs/postgresql.conf:/etc/postgresql.conf
    command: postgres -c config_file=/etc/postgresql.conf
    networks:
      - net
    ports:
      - 5432:5432 # PostgreSQL database port
    # restart: always

#  osm:
#    image: osm:latest
#    build: configs/docker/postgis
#    environment:
#      - POSTGRES_USER=siriuso
#      - POSTGRES_PASSWORD=12345
#      - POSTGRES_DB=siriuso
#      - PGDATA=/home/postgresql/data
#    volumes:
#      - osm_db:/home/postgresql
#      - osm_db:/var/log/postgresql
#    networks:
#      - net
#    ports:
#      - 5433:5432 # PostgreSQL database port

  redis:
    container_name: siriuso_cache-redis
    image: redis:alpine
    networks:
      - net
    ports:
      - 6379:6379

  rabbitmq:
    container_name: siriuso_mq-rabbitmq
    image: rabbitmq:management-alpine
    environment:
      - RABBITMQ_DEFAULT_USER=siriuso
      - RABBITMQ_DEFAULT_PASS=siriuso
#      - RABBITMQ_ERLANG_COOKIE='secret cookie here'
#      - RABBITMQ_NODENAME=tehnokom@siriuso
#      - RABBITMQ_DEFAULT_VHOST=my_vhost
#      - RABBITMQ_HIPE_COMPILE=1
    networks:
      - net
    logging:
      driver: none
    ports:
      - 5672:5672 # RabbitMQ management console
      # - 15672:15672 # RabbitMQ management console
    # restart: always

  django:
    container_name: siriuso_app-django
    build: configs/docker/python
    image: backend:latest
    # -Wa - показать предупреждения (нужно при подготовке перехода на новую версию Джанго)
    # command: python3 -Wa manage.py runserver 0.0.0.0:8000
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - ./:/home/siriuso
    networks:
      - net
    ports:
      - 8000:8000 # Django web server
    depends_on:
      - postgres
      - redis
      - rabbitmq
#      - elasticsearch
    # restart: always

  celery:
    container_name: siriuso_mq-client-celery
    build: configs/docker/python
    image: backend:latest
    # command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery -A siriuso beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --detach && celery -A siriuso worker -D "
    # command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery -A siriuso beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --detach && celery -A siriuso worker -B "
    # command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery -A siriuso beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --detach -l DEBUG --logfile=/home/siriuso/celerybeat.log  && celery -A siriuso worker -l DEBUG --logfile=/home/siriuso/celery.log "
    # command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery -A siriuso worker -l DEBUG --logfile=/home/siriuso/celery.log && celery -A siriuso beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --detach -l DEBUG --logfile=/home/siriuso/celerybeat.log  "
    # command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery -A siriuso worker -l DEBUG --logfile=/home/siriuso/celery.log && celery -A siriuso beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --detach -l INFO --logfile=/home/siriuso/celerybeat.log  "
    # command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery -A siriuso beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --detach && celery -A siriuso worker "
    # worker celery 4.4.6:
    # command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery -A siriuso worker -l info --logfile=/home/siriuso/celerybeat.log -B --scheduler django_celery_beat.schedulers:DatabaseScheduler "

    # Testing celery 5:
    command: bash -c "if [ -f "/etc/bebebe" ]; then rm /home/siriuso/celerybeat.pid; fi && celery --app siriuso worker --loglevel INFO --logfile=/home/siriuso/celerybeat.log -B --scheduler django_celery_beat.schedulers:DatabaseScheduler"
    volumes:
      - ./:/home/siriuso
    networks:
      - net
#    logging:
#      driver: none
    depends_on:
      - redis
      - rabbitmq
    # restart: always

  flower:
    container_name: siriuso_mq-mon-flower
    build: configs/docker/python
    image: backend:latest
    command: celery -A siriuso flower --port=5550
    # command: flower -A siriuso --port=5550
    volumes:
      - ./:/home/siriuso
    ports:
      - 5550:5550 # Flower
    networks:
      - net
    logging:
      driver: none
    depends_on:
      - celery
    # restart: always

# требуется выполнить sysctl -w vm.max_map_count=262144
#  elasticsearch:
#    image: docker.elastic.co/elasticsearch/elasticsearch:6.1.1
#    environment:
#      - cluster.name=siriuso
#      - bootstrap.memory_lock=true
#      - ES_JAVA_OPTS=-Xms512m -Xmx512m
#    ulimits:
#      memlock:
#        soft: -1
#        hard: -1
#    volumes:
#      - esdata:/usr/share/elasticsearch/data
#    ports:
#      - 9200:9200
#    networks:
#      - net

networks:
  net:

volumes:
  db:
  osm_db:
#   esdata:
